package com.cskaoyan.controller;

import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.service.AdminConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author : qj
 * @since: 2022/10/11  23:07
 */
@RestController
@RequestMapping("admin/config")
public class AdminConfigController {
    @Autowired
    AdminConfigService adminConfigService;

    @GetMapping("mall")
    public BaseRespVo listMall(){
        Map<String,String> map = adminConfigService.querySystemConfigNameAndValue();
        return BaseRespVo.ok(map);
    }

    @PostMapping("mall")
    public BaseRespVo updateMall(@RequestBody Map map){
         adminConfigService.updateSystemConfigValue(map);
         return BaseRespVo.ok();
    }

    @GetMapping("express")
    public BaseRespVo listExpress(){
        Map<String,String> map = adminConfigService.queryFreightMinAndValue();
        return BaseRespVo.ok(map);
    }

    @PostMapping("express")
    public BaseRespVo updateExpress(@RequestBody Map map){
        adminConfigService.updateFreightMinAndValue(map);
        return BaseRespVo.ok();
    }

    @GetMapping("order")
    public BaseRespVo listOrder(){
        Map<String,String> map = adminConfigService.queryOrder();
        return BaseRespVo.ok(map);
    }

    @PostMapping("order")
    public BaseRespVo updateOrder(@RequestBody Map map){
        adminConfigService.updateOder(map);
        return BaseRespVo.ok();
    }

    @GetMapping("wx")
    public BaseRespVo listWx(){
        Map<String,String> map = adminConfigService.queryWx();
        return BaseRespVo.ok(map);
    }

    @PostMapping("wx")
    public BaseRespVo updateWx(@RequestBody Map map){
        if (map.containsKey("market_wx_share")){
            Object market_wx_share = map.get("market_wx_share");
            String s = market_wx_share.toString();
            map.remove("market_wx_share");
            map.put("market_wx_share",s);
        }
        adminConfigService.updateWx(map);
        return BaseRespVo.ok();
    }
}
